<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link rel="stylesheet" type="text/css" href="<?php echo $this->_webroot('skin/css/admin.css'); ?>">
<link rel="stylesheet" type="text/css" href="<?php echo $this->_webroot('skin/css/main.css'); ?>">
<style>
td span {color:red;}
.green {color:green;}
.red {color:red;}
#divname{float:left; margin:0px;}
</style>
<script language="JavaScript" src="<?php echo $this->_webroot('servtools/ajax_client/ajax.js'); ?>"></script>
<script type="text/javascript">
function ltrim(str){ //删除左边的空格   
	 return str.replace(/(^\s*)/g,"");   
}
//text
function edit(obj,id,inputname,url,param,size){
	var uright=document.getElementById("update_right");
	var div1=obj.nextSibling;
	if(div1.nodeType!=1){
      div1=div1.nextSibling;
	}
	if(uright!='0'){
	obj.style.display="none";
     var spanvalue=obj.innerHTML;
     var spaninput="<input type=text id='"+inputname+"' onblur=\"editpost(this,'"+id+"','"+url+"','"+param+"');\" size="+size+" maxlength='100' value='"+spanvalue+"' />";
     div1.innerHTML=spaninput;
     div1.style.display="block";
     
     document.getElementById(inputname).focus();
  }else{
	    ShowMessageBox("对不起，您没有权限不能修改！",'m.php?app=error');
		// location.href="m.php?app=error";
	}
}
function editpost(obj,id,url,param){
	var div1=obj.parentNode;
	var span1=div1.previousSibling;
	if(span1.nodeType!=1){
		span1=span1.previousSibling;
	}
	if(obj.value==span1.innerHTML){
      div1.style.display="none";
      span1.style.display="block";
	}else{
      ajax(url,"POST",param+obj.value,function(data){
           if(data==1){
          	 div1.style.display="none";
          	 span1.innerHTML=obj.value;
               span1.style.display="block";
           }else{
          	 ShowMessageBox("更新失败",'1');
          	   div1.style.display="none";
               span1.style.display="block";
               }
      });
	}
	
}
//带有数字验证
function editnum(obj,id,inputname,url,param,size){
	var uright=document.getElementById("update_right");
	var div1=obj.nextSibling;
	if(div1.nodeType!=1){
      div1=div1.nextSibling;
	}
	if(uright!='0'){
	obj.style.display="none";
     var spanvalue=obj.innerHTML;
     var spaninput="<input type=text id='"+inputname+"' onblur=\"editpost(this,'"+id+"','"+url+"','"+param+"');\" "+
                   "size="+size+" maxlength='100' value='"+spanvalue+"' onkeypress='return regInput(this,/^[0-9]*$/,String.fromCharCode(event.keyCode))'"+
                   " onpaste= \"return regInput(this,\/^[0-9]*$/,\window.clipboardData.getData('Text'))\" ondrop= \"return regInput(this,/^[0-9]*$/,event.dataTransfer.getData('Text'))\" "+
                   " style=\"ime-mode:Disabled\" />";
     div1.innerHTML=spaninput;
     div1.style.display="block";
     
     document.getElementById(inputname).focus();
  }else{
	    ShowMessageBox("对不起，您没有权限不能修改！",'m.php?app=error');
	}
}
</script>
</head>
<body>
<input type="hidden" id="update_right" value="1" ></input>
<div id="maincontent">
	<div class="wrap">
	<div class="crumbs">当前位置 &gt;&gt; 商品管理 &gt;&gt; 商品分类列表</div>
        <hr />
	<div class="infobox">
	<h3>
	<span class="left">商品分类列表</span>
    <span style="margin-right:15px;" class="right"> 	
	<a style="float:right;" href="<?php echo $this->_url('admin/goods/categoriesadd');?>">添加分类</a>
	</span>
	</h3>
    <div class="content2">
		<table class="list_table" style='font-size:12px;'>
			<thead>
            <tr style=" text-align:center;">
				<th width="50px">ID</th>
				<th align="left">分类名称</th>
				<th width="65px">产品数量</th>
				<th width="65px">显示排序</th>
				<th width="115px">操作</th>
			</tr>
			</thead>
			<tbody>
			<?php if($category_dg) {
			foreach($category_dg as $value) { ?>
			<tr style=" text-align:center;">
				<td><?php echo $value['id'];?>.</td>
				<td align="left" <?php if($value['parent_id']=='0') {echo 'style="font-weight:bold;"';} ?>>
				<div>
				    <div id="divname"><?php echo $value['str_pad'];?>&nbsp;</div>
				    <div id="divname" onclick="edit(this,<?php echo $value['id'];?>,'divname<?php echo $value['id'];?>','a.php?act=updateAjax','tablename=shop_categories&colname=cat_name&idname=cat_id&idvalue=<?php echo $value['cat_id'];?>&logcontent=编辑分类：&colvalue=',5);"><?php echo $value['cat_name'];?></div>
				    <div id="divname" style="display:none"></div>
				</div>
				</td>
				<td><?php echo $value['goods_num'];?></td>
				<td><div onclick="editnum(this,<?php echo $value['id'];?>,'divorder<?php echo $value['id'];?>','a.php?act=updateAjax','tablename=shop_categories&colname=sort_order&idname=cat_id&idvalue=<?php echo $value['cat_id'];?>&logcontent=编辑分类：&colvalue=',2);"><?php echo $value['sort_order'];?></div>
				    <div style="display:none"></div>
				</td>
				<td>
				    <a href="<?php echo $this->_url('admin/goods/attributelist/?cat_id='.$value['id']);?>">设置属性</a>
					<a href="<?php echo $this->_url('admin/goods/categoriesedit/'.$value['id']);?>">修改</a>
					<a href="<?php echo $this->_url('admin/goods/categoriesdel/'.$value['id']);?>" onclick="return confirm('删除分类后，该分类下的店铺分类会重置。确定要删除吗？');">删除</a>
				</td>
			</tr>
			<?php }} else { ?>
			<tr>
				<td colspan="6">暂无信息</td>
			</tr>
			<?php } ?>
			</tbody>
		</table>
	  </div>
	 </div>
	</div>
</div>
</body>
</html>